package io.renren.modules.echarts.controller;


import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.echarts.entity.StudentAttendenceClassRate;
import io.renren.modules.echarts.service.AttendenceChartsService;
import io.renren.modules.jxgk.common.ZTreeNode;
import io.renren.modules.jxgk.entity.CollegeInfoEntity;
import io.renren.modules.jxgk.entity.StudentAttendenceDetailsEntity;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/AttendenceCharts")
public class AttendenceChartsController {
    @Autowired
    AttendenceChartsService attendenceChartsService;


    @RequestMapping("/getAttendanceClassRankingFirstTen")
    public R getstudentAttendence(@RequestParam Map<String, Object> params) {
        Map<String,Object> rank =attendenceChartsService.getAttendanceClassRankingFirstTen(params);
        return R.ok().put("option",rank);
    }

    @RequestMapping("/getAttendanceProfessionRankingFirstTen")
    public R getAttendanceProfessionRankingFirstTen(@RequestParam Map<String, Object> params) {
        Map<String,Object> rank =attendenceChartsService.getAttendanceProfessionRankingFirstTen(params);
        return R.ok().put("option",rank);
    }

    @RequestMapping("/getAttendanceCollageRanking")
    public R getAttendanceCollageRankingFirstTen(@RequestParam Map<String, Object> params) {
        Map<String,Object> rank =attendenceChartsService.getAttendanceCollageRanking(params);
         return R.ok().put("option",rank);
    }
    @RequestMapping("/getAttendanceCollegeHorizontalComparison")
    public R getAttendanceCollegeHorizontalComparison(@RequestParam Map<String, Object> params) {
        Map<String,List> map =attendenceChartsService.getAttendanceCollegeHorizontalComparison(params);
        return R.ok().put("r",map);
    }
    @RequestMapping("/getAttendanceClassHorizontalComparison")
    public R getAttendanceClassHorizontalComparison(@RequestParam Map<String, Object> params) {
        Map<String,List> map =attendenceChartsService.getAttendanceClassHorizontalComparison(params);
        return R.ok().put("r",map);
    }

    @RequestMapping("/getAttendanceProfessionHorizontalComparison")
    public R getAttendanceProfessionHorizontalComparison(@RequestParam Map<String, Object> params) {
        Map<String,List> map =attendenceChartsService.getAttendanceProfessionHorizontalComparison(params);
        return R.ok().put("r",map);
    }

    @RequestMapping("/getClassTree")
    public R getClassTree(@RequestParam Map<String, Object> params) {

        List<ZTreeNode> list = attendenceChartsService.getClassTree();
        return R.ok().put("r",list);
    }

    @RequestMapping("/getClassTreeByCollege")
    public R getClassTreeByCollege(@RequestParam Map<String, Object> params) {

        String college = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getCollege();
        params.put("collegeName",college);
        List<ZTreeNode> list = attendenceChartsService.getClassTreeByCollege(params);
        return R.ok().put("r",list);
    }

    @RequestMapping("/getClassTreeByGrade")
    public R getClassTreeByGrade(@RequestParam Map<String, Object> params) {

        String college = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getCollege();
        params.put("collegeName",college);
        List<ZTreeNode> list = attendenceChartsService.getClassTreeByGrade(params);
        return R.ok().put("r",list);
    }


    @RequestMapping("/getProfessionTree")
    public R getProfessionTree(@RequestParam Map<String, Object> params) {

        List<ZTreeNode> list = attendenceChartsService.getProfessionTree();
        return R.ok().put("r",list);
    }

    @RequestMapping("/getProfessionByCollege")
    public R getProfessionByCollege(@RequestParam Map<String, Object> params) {
        String college = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getCollege();
        params.put("collegeName",college);
        List<String> list = attendenceChartsService.getProfessionByCollege(params);
        return R.ok().put("r",list);
    }

    @RequestMapping("getStudentsAttendance")
    public R getStudentsAttendance(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<StudentAttendenceClassRate> cse = attendenceChartsService.getStudentsAttendanceList(query);
        int total = attendenceChartsService.getStudentsAttendanceTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
    @RequestMapping("getProfessionTreeByCollege")
    public R getProfessionTreeByCollege(@RequestParam Map<String, Object> params) {
        String college = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getCollege();

        List<ZTreeNode> list = attendenceChartsService.getProfessionTreeByCollege(college);
        return R.ok().put("r",list);
    }


}
